/**
 * Created by chen on 18/5/25.
 */
function getCartNum(allCartList)
{
  var cart_num = 0;
  for(var i = 0; i < allCartList.length; i ++)
  {
    cart_num += allCartList[i].count;
  }
  $("#cart_num").text("购物车("+ cart_num +")");
}

var promotion_barcodes = ['ITEM00001','ITEM00006'];//优惠促销barcode 买二送一
function getAllCartList(allCartList)
{
  for(var i = 0; i < allCartList.length; i ++)
  {
    var item_info = allCartList[i];
    var barcode = _.find(promotion_barcodes,function(barcode){
      return barcode == item_info.barcode;
    });
    if (barcode == undefined || item_info.count < 3)
    {
      item_info.subtotal = item_info.price * item_info.count + "元";
    }
    else
    {
      item_info.subtotal = item_info.price * (item_info.count - Math.floor(item_info.count/3))+"元（原价："
        +item_info.price * item_info.count + "元）";
    }
  }
  return allCartList;
}